﻿using System;
using System.Collections.Generic;
using Entitas;
using UnityEngine;

[Flags]
public enum BehaviorType

{
    Seek = 1 << 0,
    Flee = 1 << 1,
    Arrive = 1 << 2,
    Pursuit = 1 << 3,
    Evade = 1 << 4,
    Wander = 1 << 5,
    ObstacleAvoidance = 1 << 6,
    Interpose = 1 << 7,
    Hide = 1 << 8,
    FollowPath = 1 << 9,
    OffsetPursuit = 1 << 10,
    WallAvoidance = 1 << 11,
    Separation = 1 << 12,
    Alignment = 1 << 13,
    Cohesion = 1 << 14,
}

public class WanderParams
{
    public float wanderRadius;
    public float wanderDistance;
    public float wanderJitter;
    public Vector3 wanderTarget;
}

public class Path
{
    private List<Vector3> _wayPoints;
    private int _current;
    private bool _isLoop;

    public Path(List<Vector3> wayPoints, bool isLoop)
    {
        _wayPoints = wayPoints;
        _isLoop = isLoop;
        _current = 0;
    }

    public void NextWayPoint()
    {
        if (_current < _wayPoints.Count - 1)
        {
            _current++;
        }
        else if (_isLoop)
        {
            _current = 0;
        }
    }

    public Vector3 CurrentWayPoint()
    {
        return _wayPoints[_current];
    }

    public bool Finished()
    {
        if (_isLoop)
        {
            return false;
        }

        return _current + 1 == _wayPoints.Count;
    }
}

public class BehaviorComponent : IComponent
{
    public BehaviorType behaviors;
    public WanderParams wanderParams;
    public Path path;
    public Vector3 offset;
}